<template>
	<view class="integralInfo">
		<n-loading></n-loading>
		<view class="coinBj"></view>
		<view class="contBox">
			<!-- 签到 -->
			<view class="signInBox">
				<view class="addUpCoin">
					<view class="tit">-累计金币-</view>
					<view class="num">{{integral.coin}}</view>
					<view class="signInBtn" @tap="signInGo" v-if="isSignIn==0">今日签到</view>
					<view class="signInBtn signInBtnEd" v-if="isSignIn==1">已签到</view>
					<view class="tips">签到收取金币收益</view>
				</view>
			</view>
			<view class="pd32">
				<!-- 统计 -->
				<view class="statistics">
					<view class="each">
						<image src="https://lovebirdopen.com/static/img/svgIcon/allCoin.svg" mode=""></image>
						今日金币
						<text class="add">+{{0}}</text>
					</view>
					<view class="each">
						<image src="https://lovebirdopen.com/static/img/svgIcon/todayCoin.svg" mode=""></image>
						现有金币
						<text class="cur">{{integral.coin}}</text>
					</view>
				</view>
				<view class="pointsDetails">
					<view class="nodata" v-if="recordList.length==0">
						<image src="../../static/svgIcon/noCoupon.svg" mode=""></image>
						<view class="tips">暂无积分记录~</view>
					</view>
					<!-- 积分明细 -->
					<view class="detailsEach" v-for="(item,index) of recordList" :key="index">
						<view class="contInfo">
							<view class="title">{{item.object_type==1?'购物金币':'提现金币'}}</view>
							<view class="time">{{getdate(item.updated_at,1)}}</view>
						</view>
						<view class="addD" :class="{recD:item.status==2}">{{item.status==1?'+':'-'}}{{item.point}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				offset:1,
				url:'/api/user/moreTableList', //接口地址
				// 列表
				recordList:[],
				listReady:null,
				isLoadMore:false,
				page: 1,
				pageSize: 20,
				// 其他信息
				integral:null,
				today:null,
				isSignIn:0,
			}
		},
		onLoad() {
			// this.getGoldRecord();
			if (!uni.getStorageSync('userInfo')) {
				//用户登录
				this.login();
			} else {
				//调用默认启动方法
				this.loadData();
			}
		},
		// 滑动到底部
		onReachBottom() {
			if(!this.isLoadMore){
				this.offset++
				this.get_indexData()();
			}
		},
		methods: {
			loadData(){
				this.get_indexData()
				this.get_miniData()
			},
			//用户金币记录
			async get_indexData() {
				//-------主表查询参数-------------banner参数
				let param = {};
				param.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				param.dbNum = ''; //缓存编号   API默认以MD5(param)为编号
				param.table = 'user_fund_log';//主表名称
				param.listType = 3; //2查询全部  3分页查询
				param.offset=this.offset;
				param.limit=10;
				param.order = ''; //表无自增ID时追加为默认排序 无需给个字符空值
				param.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				param.where = {'user_id':uni.getStorageSync('userInfo').user_id,'type':4}; //主表查询条件 无需给个字符空值
				param.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				//----------请求banner
				const res = await this.$fly.post(this.url, { 
					msg: JSON.stringify(param)
				});
			
				//--------------------------------banner数据组装
				if (res.code == 200) {
					this.isLoadMore = true;
					if(this.offset==1){
						this.recordList=res.data
					}else{
						this.recordList=this.recordList.concat(res.data)
					}
					if(this.recordList.length>=tes.sl){
						this.isLoadMore = true;
					}
					// console.log(res.data)
				} else {  
					console.log(res);
				}
			},
			
			// 个人资产
			async get_miniData(){
				let user_id=uni.getStorageSync('userInfo').user_id
				
				//-------主表查询参数-------------个人资产
				let params = {};
				params.db = 1; //0获取缓存数据  1 获取非缓存数据  默认0
				params.dbNum = ''; //缓存编号   API默认以MD5(paramActivity)为编号
				params.table = 'user_fund';//主表名称
				params.listType = 2; //2查询全部  3分页查询
				params.order = 'user_id Asc'; //表无自增ID时追加为默认排序 无需给个字符空值
				params.linkfield = ''; //主表关联字段名称（为空则非关联多表查询）
				params.where = {'user_id':user_id}; //主表查询条件 无需给个字符空值
				params.table_list =[];//多表参数数组名称 无需给个字符空或空数组
				
				//----------请求个人资料
				const res = await this.$fly.post(this.url, { 
					msg: JSON.stringify(params)
				});
				
				if (res.code == 200) {
					this.integral=res.data[0]
					console.log(res,"mine")
				} else {
					console.log(res,"error")
				}
			},
			
			
			// 用户金币记录
			getGoldRecord(){
				this.apiget('/fun/member/integral',{page:this.page,pageSize:this.pageSize}).then(res =>{
					if(res.data.status == 200 ) {
						if(this.page==1){
							this.integral = res.data.data.integral;
							this.today = res.data.data.today;
							this.isSignIn = res.data.data.isSignIn;
						}
						this.recordList = this.recordList.concat(res.data.data.list);
						this.listReady = 1;
						if(res.data.data.list.length<this.pageSize){
							this.isLoadMore = true;
							this.status = 'nomore';
						}else if(res.data.data.list.length==this.pageSize && this.page == res.data.data.pageCount){
							this.isLoadMore = true;
							this.status = 'nomore';
						}else{
							this.status = 'loading';
							this.page = ++ this.page;
						}
					}
				})
			},
			// 签到
			signInGo(){
				var _this = this;
				this.apipost('/fun/member/sign-in',{}).then(res =>{
					if(res.data.status == 200 ) {
						uni.showToast({
							icon: 'success',
							duration:1000,
							title: '签到成功',
							success: res => {
								setTimeout(function (){
									_this.recordList = [];
									_this.page = 1;
									_this.getGoldRecord();
								}, 1000);
							},
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.integralInfo{
		min-height: 100%;
		background: #F8F8FA;
	}
	.coinBj{
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 680rpx;
		background: linear-gradient(180deg, #FFCB05 0%, rgba(255, 203, 3, 0.5) 69.79%, rgba(255, 240, 107, 0) 100%);
		
	}
	.contBox{
		position: relative;
	}
	// 签到
	.signInBox{
		height: 420rpx;
		padding-top: 14rpx;
		background: url('https://lovebirdopen.com/static/img/cBj/signInBj.png') no-repeat;
		background-size: 100% 100%;
		
		.addUpCoin{
			width: 320rpx;
			margin: 0 auto;
			padding-top: 116rpx;
			text-align: center;
			color: #FFFFFF;
			background: url('https://lovebirdopen.com/static/img/cBj/signInStarBj.png') no-repeat top center;
			background-size: 100% 320rpx;
			
			.tit{
				margin-bottom: 4rpx;
				font-size: 24rpx;
				line-height: 40rpx;
			}
			.num{
				margin-bottom: 36rpx;
				font-size: 56rpx;
				line-height: 64rpx;
			}
			.signInBtn{
				display: inline-block;
				width: 192rpx;
				height: 68rpx;
				margin-bottom: 4rpx;
				line-height: 68rpx;
				font-size: 28rpx;
				background: linear-gradient(132.26deg, #FF8038 19.89%, #FF5238 75.38%);
				border-radius: 50rpx;
			}
			.signInBtnEd{
				background: #d8d8d8;
			}
			.tips{
				font-size: 24rpx;
				line-height: 40rpx;
			}
		}
	}
	.pd32{
		padding: 0 32rpx;
	}
	// 统计
	.statistics{
		padding: 22rpx 0;
		height: 96rpx;
		margin-bottom: 24rpx;
		background: #FFFFFF;
		box-shadow: 0px 4rpx 16rpx rgba(255, 82, 56, 0.02);
		border-radius: 86rpx;
		
		.each{
			float: left;
			display: flex;
			width: 50%;
			height: 48rpx;
			font-size: 22rpx;
			color: #999999;
			align-items: center;
			justify-content: center;
			
			image{
				display: inline-block;
				width: 48rpx;
				height: 48rpx;
				margin-right: 8rpx;
			}
			
			text{
				margin-left: 8rpx;
				font-size: 36rpx;
			}
			
			.add{
				color: #FBB11B;
			}
			
			.cur{
				color: #FF5238;
			}
		}
	}
	// 积分明细
	.pointsDetails{
		margin-top: 32rpx;
		background: #fff;
		border-radius: 16rpx;
		
		.detailsEach{
			display: flex;
			align-items: center;
			padding: 20rpx 32rpx 26rpx;
			box-shadow: inset 0px -0.5px 0px #ECEEF0;
			
			.contInfo{
				flex: auto;
				
				.time{
					font-size: 24rpx;
					line-height: 40rpx;
					color: #999;
				}
				.title{
					font-size: 28rpx;
					line-height: 40rpx;
					color: #333;
				}
			}
			.addD{
				font-weight: bold;
				font-size: 28rpx;
				color: #333;
			}
			.recD{
				color: #FF5238;
			}
		}
	}
	
</style>
